package com.mairuide.menuinfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mairuide._frame.base.BaseController;
import com.mairuide._frame.utils.StringUtils;
import com.mairuide.agency.service.AgencyService;

@Controller
@RequestMapping("/menuInfo")
public class MenuInfoController extends BaseController {
	
	@Autowired
	private MenuInfoService menuInfoService;
	
	/**
	 * 模糊查询当前用户所属权限下的菜单信息
	 * @param chatSend
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getMenuName4Like", method = RequestMethod.POST)
	public Object getMenuName4Like(@RequestParam(defaultValue="") String chatSend) {
		if(StringUtils.isEmpty(chatSend)) {
			return ERROR("chatSend is empy");
		}
		Map<String, Object> result = new HashMap<String, Object>();
		// 通过userId查询菜单权限
		List<MenuInfo> menuInfoList = new ArrayList<>();
		List<MenuInfo> mis = menuInfoService.findByUserId(super.getLoginUser().getId());
		if(null != mis && mis.size() > 0) {
			for(MenuInfo mi : mis) {
				if(mi.getMenuLevel() == 3) {
					menuInfoList.add(mi);
				}
			}
			menuInfoList = menuInfoService.getMenuInfoByMenuNameLike(chatSend.trim(), menuInfoList);
			result.put("mil",menuInfoList);
		}
		return result;
	}
}
